<?php


namespace app\front\controller;


use app\BaseController;
use app\exception\HttpExceptions;
use app\model\Manager;
use app\model\Notice;
use think\facade\Db;
use think\Request;

class Home extends BaseController
{
    // 用户首页
    public function info(Request $request) {
        $data = Db::name('setting')->where('page','home')->find();
        $data['slogan'] = $data['slogan'] == '' ? [] : explode('$8$',$data['slogan']);
        $data['img'] = $request->domain(true).$data['img'];
        return $this->result($data);
    }
    public function detail(Request $request) {
        $data = Db::name('setting')->where('page','detail')->find();
        $data['slogan'] = $data['slogan'] == '' ? [] : explode('$8$',$data['slogan']);
        $data['img'] = $request->domain(true).$data['img'];
        return $this->result($data);
    }
    public function noticeList (Request $request) {
        $data = $request->get(['page','size']);
        if( !isset($data['page'])|| !isset($data['size'])) {
            throw new HttpExceptions('参数不合法');
        }
        if($data['page'] < 1) {
            throw new HttpExceptions('参数不合法');
        }
        $result = Notice::pageList($data['page'],$data['size']);
        return $this->result($result);
    }

//    public function useCoin() {
//        $data = Db::name('user')->find($this->uid);
//        $data = array_diff_key($data,['id' => 'xxx']);
//        $data = array_diff_key($data,['openid' => 'xxx']);
//        $data = array_diff_key($data,['uname' => 'xxx']);
//        $data = array_diff_key($data,['is_notice' => 'xxx']);
//        return $this->result($data);
//    }
//
//    public function advise(Request $request) {
//        $advise = $request -> post('advise');
//        $uid = $this->uid;
//        if(!isset($advise) || $advise == '') {
//            throw  new HttpExceptions('非法传参');
//        }
//
//        $create_time = date('Y-m-d h:i:s', time());
//        Db::name('advise')->save(compact('uid','advise','create_time'));
//        $manger = Manager::find(1);
//        $manger -> advise = $manger->advise + 1;
//        $manger->save();
//        return $this->result();
//    }

}